package com.chinatelecom.telecollege.sellerrewarding.controller;

import com.chinatelecom.telecollege.sellerrewarding.Entity.product;
import com.chinatelecom.telecollege.sellerrewarding.service.productService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by lenovo on 2017/6/21.
 */
@RestController
public class productController {
    @Autowired
    private productService productService;

    @RequestMapping(value = "/product")
    public product queryproduct(@RequestParam int id) {
        return productService.find(id);
    }

    @RequestMapping(value = "/productall")
    public List<product> queryproductall() {
        return productService.findAll();
    }

    @RequestMapping(value = "/productadd")
    public String addproduct(@RequestParam String name,
                          @RequestParam int reward) {
        productService.save( name, reward);
        return "Success";
    }

    @RequestMapping(value = "/productdel")
    public String delproduct(@RequestParam int id) {
        productService.delete(id);
        return "Success";
    }

    @RequestMapping(value = "/productmod")
    public String modproduct(@RequestParam int id,
                             @RequestParam int reward) {
        productService.mod(id, reward);
        return "Success";
    }
}
